package org.reliablesource.prism.gef.editor;

import org.eclipse.gef.tools.AbstractTool;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.PlatformUI;
import org.reliablesource.prism.gef.editor.commands.LoadBackgroundImageCommand;


/**
 * 
 * This tool allow to load new background image.
 * @author Dennis Park
 *
 */
public class LoadBackgroundImageTool extends AbstractTool {

	static String [] FilterExtensions	= {"*.jpg", "*.bmp", "*.png"};
	static String [] FilterNames		= {"JPG Files",
										   "BMP Files",
										   "PNG Files"};
	
	public LoadBackgroundImageTool() {
		super();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
	 */
	
	protected String getCommandName() {
		return "Load Background Image";
	}
	
	public void activate(){
		super.activate();
		FileDialog dialog = new FileDialog (PlatformUI.getWorkbench().getDisplay().getActiveShell());
		dialog.setFilterNames (FilterNames);
		dialog.setFilterExtensions (FilterExtensions);
		dialog.setText ("Load background image");
		String result = dialog.open();
		
		if(result!=null)
			this.executeCommand(new LoadBackgroundImageCommand(PrismScreenEditor.instance.getModel(), result));
		
		setState(STATE_TERMINAL);
		handleFinished();
	}
	

}
